package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import model.Model;
import model.entity.Entity;
import model.entity.stats.StatType;
import model.entity.stats.StatWithMax;

public class StatsOverlay extends Overlay{
	//private Dimension overlaySize;
	//private Rectangle rect;
	private Entity e;
	private Point upperLeft;
	private int statYSpacing;
	private int lineWidth;
	private int BAR_SIZE;
	
	public StatsOverlay(Dimension size, Entity e, Point upperLeft, int statYSpacing) {
		super(size);
		this.e = e;
		//overlaySize = new Dimension(250, 100);  //TODO Hardcoded, change when needed
		this.upperLeft = upperLeft;
		//rect = new Rectangle(upperLeft, overlaySize);
		this.lineWidth = 2;
		this.BAR_SIZE = 255;
		if (statYSpacing > 100)
			statYSpacing = 100;
		else 
			this.statYSpacing = statYSpacing;
	}
	public void onResize() {
		
	}
	@Override
	protected void drawOverlay(Graphics g) {
		//g.setColor(Color.yellow); ///debug purposes
		//draw3DRect(g, rect, true); ///debug purposes
		StatWithMax HP = (StatWithMax)(e.getStat(StatType.HP));
		StatWithMax MP = (StatWithMax)(e.getStat(StatType.MP));
		
		g.setColor(Color.black);
		//Draw the background for stat bar
		g.fillRect(upperLeft.x, upperLeft.y, BAR_SIZE+this.lineWidth, 30);
		if ((double)(HP.getValue()/HP.getMaxValue()) > .5)
			g.setColor(Color.green);
		else if ((double)(HP.getValue()/HP.getMaxValue()) > .2)
			g.setColor(Color.yellow);
		else 
			g.setColor(Color.red);
		
		//Draw current health for stat bar
		int healthPixel = (int)(BAR_SIZE*(HP.getValue()/HP.getMaxValue()));
		g.fillRect((int)(upperLeft.getX()+1), upperLeft.y + this.lineWidth,healthPixel, 26);
		
		//Mana Bar
		g.setColor(Color.black);
		g.fillRect(upperLeft.x, upperLeft.y+this.statYSpacing, BAR_SIZE + this.lineWidth, 30);
		g.setColor(Color.BLUE);
		int manaPixel = (int)(BAR_SIZE*(MP.getValue()/MP.getMaxValue()));
		g.fillRect((int)(upperLeft.getX()+this.lineWidth), (int)(upperLeft.getY()+this.statYSpacing+this.lineWidth), manaPixel, 26);
	}
	private void draw3DRect(Graphics g, Rectangle rect, boolean raised) {
		g.draw3DRect((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight(), raised);
		//Log.out(Log.VIEW, rect.getLocation().toString());
	}
	private void drawRect(Graphics g, Rectangle rect) {
		g.drawRect((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight());
	}
	@Override
	public void update(Model m) {
		// TODO Auto-generated method stub
		
	}
}
